/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_handlers
 * FILE       : WpTypeSevenImpl.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Sep 29, 2011  mycodetalks			       Created
 */
package net.lwf.handler.wp.helper.general;

import net.lwf.entity.QuestionInfo;
import net.lwf.handler.wp.helper.IWordProblem;
import net.lwf.hibernate.entity.wp.WpData;
import net.lwf.number.util.RandomNumberGenerator;

/**
 * This type generates two values which are to be added to get the result.
 * val4 - (val2 + val3 + val1)
 */
public class WpAddSubtractTwoImpl extends ArithmaticWp implements IWordProblem {

	public QuestionInfo generate(WpData wpdata) {
		String[] minmax = extractData(wpdata.getDataInput());

		int val1 = RandomNumberGenerator.generate(Integer.parseInt(minmax[0]), Integer.parseInt(minmax[1]));
		int val2 = RandomNumberGenerator.generate(Integer.parseInt(minmax[0]), Integer.parseInt(minmax[1]));
		int val3 = RandomNumberGenerator.generate(Integer.parseInt(minmax[0]), Integer.parseInt(minmax[1]));

		int nAnswer = RandomNumberGenerator.generate(Integer.parseInt(minmax[0]), Integer.parseInt(minmax[1]));
		int val4 = (val1 + val2 + val3) + nAnswer;
		
		String question = wpdata.getProblem();
		String[] svalues = {String.valueOf(val1), String.valueOf(val2), String.valueOf(val3), String.valueOf(val4)};
		
		return setQuestionInfo(question, wpdata.getReplacements(), svalues, String.valueOf(nAnswer), false);
	}
	
}
